package org.kjtc.util;

import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

/**
 * 读取XML文件
 *
 */
public class ReadXml {
	public static Document doc = null;
	public static String ip;//IP
	public static int port;//端口
	public static int webFrontPort;//回复消息端口

	static{
		getXml();
	}

	public static Document readXml(){
		try {
			ReadXml readXml = new ReadXml();
			InputStream in = null;
			in = readXml.getClass().getResourceAsStream("/config.xml");
//			File file = new File("D://config.xml");
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			DocumentBuilder builder =  factory.newDocumentBuilder();
			doc = builder.parse(in);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return doc;
	}

	public static void getXml(){
		doc = readXml();
		ip = doc.getElementsByTagName("db").item(0).getFirstChild().getNodeValue();
		String port1 = doc.getElementsByTagName("db").item(1).getFirstChild().getNodeValue();
		port = Integer.parseInt(port1);
		String FrontPort = doc.getElementsByTagName("db").item(1).getFirstChild().getNodeValue();
		webFrontPort = Integer.parseInt(FrontPort);
	}
}
